<!--弹出框 新增修改删除 -->
<template>
  <div class="popupbox">
    <van-action-sheet v-model="show" :title="title" @close="hadleClosed" style="height: 90%" cancel-text="保存" @cancel="hadleConfirm">
      <div class="content">
        <inputSelect :isShowCity="false" :contentData.sync="contentData" :JFData.sync="JFData" :title="title" @getValues="getValues" @getButtons="getButtons" />
      </div>
      <!-- <div style="position: absolute; bottom: 0px; left: 50%; transform: translateX(-50%)">
          <van-button style="width: 90vw" type="info" @click="hadleConfirm">保存</van-button>
      </div> -->
    </van-action-sheet>
  </div>
</template>

<script>
import { GSA_Search, GSA_Add } from '@/common/commonApi'
import inputSelect from './inputSelect'
import { v4 as uuidv4 } from 'uuid'
export default {
  data() {
    return {
      //新增还是修改
      isAdd: true
    }
  },
  props: {
    show: {
      type: Boolean,
      default: false
    },
    AllData: {
      type: Array,
      default: function () {
        return []
      }
    },
    title: {
      type: String,
      default: '提示'
    },
    contentData: {
      type: Array,
      default: function () {
        return [
          {
            label: '规划区',
            key: 'GHQ', //绑定的字段
            ISinput: true, //true:输入框
            required: false, //true: 必填项
            readonly: false, //true:可以填写 false：不可以填写
            isTime: false //true:可以时间选择器 false：下拉框
          },
          {
            label: '建筑结构',
            key: 'jzjg',
            ISinput: false,
            required: false,
            readonly: false,
            isTime: false,
            emitData: 'b65d1943-66f4-49b1-b759-cd9f079dc0d3',
            NYDARR: []
          }
        ]
      }
    },
    JFData: {
      type: Array,
      default: function () {
        return []
      }
    },
    handleSelectClose: Function,
    //当前行的数据
    rowData: {
      type: Object
    },
    //需要查询和保存的视图
    dataguid: String
  },
  components: {
    inputSelect
  },
  methods: {
    getValues(name, value, label) {
      console.log(name, value, label, this.JFData)
    },
    getButtons() {},
    hadleClosed() {
      this.handleSelectClose()
    },
    async hadleConfirm() {
      let me = this
      if (me.isAdd) {
        delete me.JFData[0].PKID
        me.JFData[0].TO_ROW_GUID = me.rowData.ROW_GUID
        me.JFData[0].ROW_GUID = uuidv4()

        // this.JFData[0].TO_ROW_GUID =
      } else {
      }
      const res = await GSA_Add(me.dataguid, me.isAdd, ...me.JFData)
      if (res) {
        me.isAdd = false
      }
    },
    async getdata() {
      let me = this
      let data = [{ field: 'TO_ROW_GUID', value: me.rowData.ROW_GUID, link: 'AND' }]
      if (me.rowData.JJZCS_DICNAME) {
        data.push({ field: 'CS', value: me.rowData.JJZCS_DICNAME })
      }
      const res = await GSA_Search(this.dataguid, data)
      console.log(res, 'ceshi')
      try {
        if (res?.Data.length > 0) {
          this.isAdd = false
          for (let i in res.Data[0]) {
            for (let j in this.JFData[0]) {
              if (i != 'ADDRESS' && i != 'JZMJ' && i != 'FJZDMJ'&&i!='BBDYMC' && i == j) {
                this.JFData[0][j] = res.Data[0][i]
              }
            }
          }
        } else {
          this.isAdd = true
        }
      } catch (err) {}
      this.JFData[0].CS = me.rowData.JJZCS_DICNAME
    }
  },
  created() {
    //判断是一层立模
    let me = this
    if (this.title == '农村住宅设计条件书') {
      console.log(me.AllData, '农村住宅设计条件书')
      this.JFData[0].ADDRESS = me.AllData[0].HOMEADDRESS
      this.JFData[0].JZMJ = me.AllData[0].JZMJ
      this.JFData[0].FJZDMJ = me.AllData[0].FJZDMJ
      this.JFData[0].BBDYMC = me.AllData[0].XM
      console.log(this.JFData[0], 'cmvioedjnfviendriu')
    }
    this.getdata()
  }
}
</script>

<style>
.popupbox {
  .content {
    height: 90vh !important;
  }
  .van-action-sheet__cancel {
    background-color: #1989fa;
    color: #fff;
  }
}
</style>
